//
//  SearchForDiseaseDetailVC.m
//  RoadMaintain
//
//  Created by 岳学坤 on 2017/3/9.
//  Copyright © 2017年 岳学坤. All rights reserved.
//

#import "SearchForDiseaseDetailVC.h"
#import "PutNormolForIPhoneCell.h"
#import "SearchForDiseaseAddPicsForIPhoneCell.h"
#import "SearchForDiseaseForIPhoneCell.h"
#define PutCellID @"cellid1"
#define PicCellID @"cellid2"
#define DetailCellID @"cellid3"
#define kAlphaNum @".0123456789"
@interface SearchForDiseaseDetailVC ()<DetailForIPhoneCellDelegate,PicsForIPhoneDelegate,UIAlertViewDelegate,LocationForIPhoneDelegate>
{
    UIAlertView *startAlert;
    NSString * _status;//0 保存  1  上报
}

@property (nonatomic,strong)  NSString *latitude;//维度
@property (nonatomic,strong)  NSString *longitude;//经度

@property (nonatomic,strong) UIView *footerView;
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSMutableArray *imgArray;
@property (nonatomic,strong) NSString *detail;
@property (nonatomic,strong) NSDictionary *dic;//获取的需要展示的ID字典
@property (nonatomic,strong) NSString* dmdiseaseFormId;//病害形式
@property (nonatomic,strong) NSString* bdRouteId;//路线
@property (nonatomic,strong) NSString* dictDiseaseTypeId;//损坏类型
@property (nonatomic,strong) NSString* damageDegreeId;//损坏程度
@property (nonatomic,strong) NSString* dictDiseaseUnitId;//计量单位
@property (nonatomic,strong) NSString* dictDrivingDirectionId;//行车方向
@property (nonatomic,strong) NSString* dictLanePositionId;//车道位置
@property (nonatomic,strong) NSString* dictWeatherCodeId;//天气
@property (nonatomic,strong) NSString* maintainOrgId;//管养单位
@property (nonatomic,strong) NSString* dmdiseaseFormName;//病害形式
@property (nonatomic,strong) NSString* bdRouteName;//路线
@property (nonatomic,strong) NSString* dictDiseaseTypeName;//损坏类型
@property (nonatomic,strong) NSString* damageDegreeName;//损坏程度
@property (nonatomic,strong) NSString* dictDiseaseUnitName;//计量单位
@property (nonatomic,strong) NSString* dictDrivingDirectionName;//行车方向
@property (nonatomic,strong) NSString* dictLanePositionName;//车道位置
@property (nonatomic,strong) NSString* dictWeatherCodeName;//天气
@property (nonatomic,strong) NSString* maintainOrgName;//管养单位
@property (nonatomic,strong) NSString* receiveDepartment;//接收部门
@property (nonatomic,strong) NSString* receiveDepartmentId;//接收部门id
@property (nonatomic,strong) NSString* receiveMan;//接收人
@property (nonatomic,strong) NSString* receiveManId;//接收人id


@property (nonatomic,strong) NSString *startName;//起始桩号
@property (nonatomic,strong) NSString *endName;//终止桩号
@property (nonatomic,strong) NSString *num;//数量
@property (nonatomic,strong) NSString *time;//巡查日期
@property (nonatomic,strong) NSString *peopleName;//巡查人
@property (nonatomic,strong) NSString *peopleId;//巡查人id

@property (nonatomic,strong) NSMutableArray* dmdiseaseFormArray;//病害形式
@property (nonatomic,strong) NSMutableArray* bdRouteArray;//路线
@property (nonatomic,strong) NSMutableArray* dictDiseaseTypeArray;//损坏类型
@property (nonatomic,strong) NSMutableArray* dictDiseaseUnitArray;//计量单位
@property (nonatomic,strong) NSMutableArray* dictDrivingDirectionArray;//行车方向
@property (nonatomic,strong) NSMutableArray* dictLanePositionArray;//车道位置
@property (nonatomic,strong) NSMutableArray* dictWeatherCodeArray;//天气
@property (nonatomic,strong) NSMutableArray* maintainOrgArray;//管养单位数组
@property (nonatomic,strong) NSMutableArray * deleteArray;//删除的图片数组
@property (nonatomic,strong) NSMutableArray * receiveDepartmentArray; //接收部门
@property (nonatomic,strong) NSMutableArray * receiveManArray;  //接收人

@end

@implementation SearchForDiseaseDetailVC

#pragma mark - Life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self resetNav];
    LocationManager *locationManager = [LocationManager shareStartLocation];
    locationManager.locManagerFailed = ^(){
        //定位失败 无法定位当前位置
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"无法定位到您当前的位置" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        
    };
    locationManager.locManagerSucceed = ^(AddressInfo *addressInfo){
        //定位成功
        self.latitude = addressInfo.latitude;
        self.longitude = addressInfo.longitude;
    };
    locationManager.notAllow = ^(){
        //不允许定位
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请到隐私设置定位权限的开关" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        
    };

    [self setAddWebData];
    if (self.state==0) {
      [self setTableViewFooterView];
    }else if (self.state == 1){
        [self setTableViewFooterView];
        [self setRightBtnTitle:@"删除"];
    }else{
    
    }
   
}
#pragma mark - Property
- (NSArray *)titleArray{
    if (_titleArray==nil) {
        _titleArray = @[@"路线编码",@"管养单位",@"接收部门",@"接收人",@"行车方向",@"起点桩号",@"终点桩号",@"损坏类型",@"病害形式",@"损坏程度",@"计量单位",@"车道位置",@"数量",@"巡查人",@"巡查日期",@"天气"];
    }
    return _titleArray;
}
- (NSMutableArray *)receiveManArray{
    if (_receiveManArray == nil) {
        _receiveManArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _receiveManArray;
}
- (NSMutableArray *)receiveDepartmentArray{
    if (_receiveDepartmentArray == nil) {
        _receiveDepartmentArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _receiveDepartmentArray;
}
- (NSMutableArray *)imgArray{
    if (_imgArray==nil) {
        _imgArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _imgArray;
}
- (NSMutableArray *)dmdiseaseFormArray{
    if (_dmdiseaseFormArray==nil) {
        _dmdiseaseFormArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _dmdiseaseFormArray;
}
- (NSMutableArray *)bdRouteArray{
    if (_bdRouteArray==nil) {
        _bdRouteArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _bdRouteArray;
}
- (NSMutableArray *)dictDiseaseTypeArray{
    if (_dictDiseaseTypeArray==nil) {
        _dictDiseaseTypeArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _dictDiseaseTypeArray;
}
- (NSMutableArray *)dictDiseaseUnitArray{
    if (_dictDiseaseUnitArray==nil) {
        _dictDiseaseUnitArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _dictDiseaseUnitArray;
}
- (NSMutableArray *)dictDrivingDirectionArray{
    if (_dictDrivingDirectionArray==nil) {
        _dictDrivingDirectionArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _dictDrivingDirectionArray;
}
- (NSMutableArray *)dictLanePositionArray{
    if (_dictLanePositionArray==nil) {
        _dictLanePositionArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _dictLanePositionArray;
}
- (NSMutableArray *)dictWeatherCodeArray{
    if (_dictWeatherCodeArray==nil) {
        _dictWeatherCodeArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _dictWeatherCodeArray;
}
- (NSMutableArray *)maintainOrgArray{
    if (_maintainOrgArray==nil) {
        _maintainOrgArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _maintainOrgArray;
}
- (NSMutableArray *)deleteArray{
    if (_deleteArray == nil) {
        _deleteArray = [[NSMutableArray alloc]initWithCapacity:1];
    }
    return _deleteArray;
}
#pragma mark - UI
- (void)resetNav{
    [self setTheBackBtn];
    self.myTitle.text = @"病害巡查";
    [self.tableView registerClass:[PutNormolForIPhoneCell class] forCellReuseIdentifier:PutCellID];
    [self.tableView registerClass:[SearchForDiseaseAddPicsForIPhoneCell class] forCellReuseIdentifier:PicCellID];
    [self.tableView registerClass:[SearchForDiseaseForIPhoneCell class] forCellReuseIdentifier:DetailCellID];
}
- (void)setTableViewFooterView{
    
    self.footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 200*WidthRate)];
    self.footerView.backgroundColor = [PublicMethod colorWithHexString:@"#eaeaea" andAlpha:1];
    self.tableView.tableFooterView = self.footerView;
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.layer.cornerRadius = 5;
    saveBtn.layer.masksToBounds = YES;
    saveBtn.layer.borderColor = [MAIN_Color CGColor];
    saveBtn.layer.borderWidth = 1;
    saveBtn.backgroundColor = Bai_Color;
    [saveBtn setTitleColor:MAIN_Color forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:17*ZitiRate];
    [self.footerView addSubview:saveBtn];
    [saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-120*WidthRate);
        make.height.mas_equalTo(42*WidthRate);
        make.left.mas_equalTo(22*WidthRate);
        make.right.equalTo(self.footerView.mas_centerX).offset(-15*WidthRate);
    }];
    
    
    UIButton *submit = [UIButton buttonWithType:UIButtonTypeCustom];
    submit.layer.cornerRadius = 5;
    submit.layer.masksToBounds = YES;
    submit.backgroundColor = MAIN_Color;
    [submit setTitleColor:Bai_Color forState:UIControlStateNormal];
    [submit setTitle:@"上报" forState:UIControlStateNormal];
    [submit addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    submit.titleLabel.font = [UIFont systemFontOfSize:17*ZitiRate];
    [self.footerView addSubview:submit];
    [submit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-120*WidthRate);
        make.height.mas_equalTo(42*WidthRate);
        make.right.mas_equalTo(-22*WidthRate);
        make.left.equalTo(self.footerView.mas_centerX).offset(15*WidthRate);
    }];
}

#pragma mark - UI Response
- (void)rightButtonClick{
    UIAlertView *deleteAlert = [[UIAlertView alloc]initWithTitle:@"删除" message:@"确定删除当前保存的草稿？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [deleteAlert show];
  
}
- (void)save{
    _status = @"0";
    [self putData];
}
- (void)submit{
    _status = @"1";
    [self putData];
}
- (void)putData{
   

    if ([self.bdRouteId length]==0) {
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"路线编码不能为空。" animated:YES];
    }else if([self.maintainOrgId length]==0){
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"管养单位不能为空。" animated:YES];
    }else if([self.dictDrivingDirectionId length]==0){
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"行车方向不能为空。" animated:YES];
    }else if([self.startName length]==0){
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"起点桩号不能为空" animated:YES];
    }else if([self.endName length]==0){
        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"终点桩号不能为空。" animated:YES];
    }else if([self.dictDiseaseTypeId length]==0){
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"损坏类型不能为空。" animated:YES];
    }else if([self.dmdiseaseFormId length]==0){
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"病害形式不能为空。" animated:YES];
    }else if([self.dictLanePositionId length]==0){
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"车道位置不能为空。" animated:YES];
    }else if([self.num length]==0){
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"数量不能为空。" animated:YES];
    }else if([self.dictWeatherCodeId length]==0){
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"天气不能为空。" animated:YES];
    }else if([self.time length]==0){
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"巡查日期不能为空。" animated:YES];
    }else{
        if ([_status integerValue]==1) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"上报" message:@"您确定上报此病害巡查单吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
            
        }else{
                [self endPutData];
        }
        
    }

}
- (void)endPutData{
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    NSMutableArray * addImgArray = [[NSMutableArray alloc]initWithCapacity:1];
    for (int i = 0; i<self.imgArray.count; i++) {
        if ([self.imgArray[i] isKindOfClass:[UIImage class]]) {
            [addImgArray addObject:self.imgArray[i]];
        }
    }
    
    [NetWorkTool putUpSearchForDisease:self.codeId routeId:self.bdRouteId maintainUnitId:self.maintainOrgId receiveDepartmentId:self.receiveDepartmentId receiveUser:self.receiveManId diseaseTypeCode:self.dictDiseaseTypeId drivingDirectionCode:self.dictDrivingDirectionId startStake:self.startName endStake:self.endName diseaseFormId:self.dmdiseaseFormId diseaseLevelCode:self.damageDegreeId diseaseUnitCode:self.dictDiseaseUnitId lanePositionCode:self.dictLanePositionId num:self.num remark:self.detail weatherCode:self.dictWeatherCodeId state:_status time:self.time inspectionUser:self.peopleId  block:^(id data) {
        
        if (data) {
            if ([data[@"success"]integerValue]) {
                
                [NetWorkTool userHeadImg:addImgArray deleteArr:self.deleteArray billId:data[@"data"] billType:@"dmDamageInspection" success:^(NSDictionary *responseObject) {
                    [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                    if ([_status integerValue]==0) {
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"保存成功" animated:YES];
                    }else{
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"上报成功" animated:YES];
                    }
                    [self performSelector:@selector(pop) withObject:nil afterDelay:1];
                } failure:^(NSError *error) {
                      [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，操作失败。" animated:YES];
                } uploadProgressBlock:^(float uploadPercent, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
                    
                }];
                
            }else{
                  [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }
            }
        }else{
              [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，操作失败。" animated:YES];
        }
    }];

}

- (void)pop{
       [self.navigationController popViewControllerAnimated:YES];
}
- (void)gotoLogin{
  [PublicMethod noTokenToLoginWithNav:self.navigationController];
}
#pragma mark - Data handle
- (void)setWebData{
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    [NetWorkTool getSearchForDiseaseDetailWithID:self.codeId block:^(id data) {
        [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
        if (data) {
            if ([data[@"success"] integerValue]) {
                self.dic = data[@"data"][@"dmDamageInspection"];
                self.dmdiseaseFormId = self.dic[@"diseaseFormId"];
                self.dmdiseaseFormName = self.dic[@"diseaseFormName"];
                self.bdRouteId = self.dic[@"routeId"];
                self.bdRouteName = self.dic[@"routeCode"];
                self.dictDiseaseTypeId = self.dic[@"diseaseTypeCode"];
                self.dictDiseaseTypeName = self.dic[@"diseaseTypeName"];
                self.damageDegreeId = self.dic[@"diseaseLevelCode"];
                self.damageDegreeName = self.dic[@"diseaseLevelName"];
                self.dictDiseaseUnitId = self.dic[@"diseaseUnitCode"];
                self.dictDiseaseUnitName = self.dic[@"diseaseUnitName"];
                self.dictDrivingDirectionId = self.dic[@"drivingDirectionCode"];
                self.dictDrivingDirectionName = self.dic[@"drivingDirectionName"];
                self.dictWeatherCodeId = self.dic[@"weatherCode"];
                self.dictWeatherCodeName = self.dic[@"weatherName"];
                self.dictLanePositionId = self.dic[@"lanePositionCode"];
                self.dictLanePositionName = self.dic[@"lanePositionName"];
                self.maintainOrgId = self.dic[@"maintainUnitId"];
                self.maintainOrgName = self.dic[@"maintainUnitName"];
                self.receiveDepartmentId = self.dic[@"receiveDepartmentId"];
                self.receiveManId = self.dic[@"receiveUser"];
                self.receiveDepartment = self.dic[@"receiveDepartmentName"];
                self.receiveMan = self.dic[@"receiveUserName"];
                
                self.startName = [NSString stringWithFormat:@"%@",self.dic[@"startStake"]] ;
                self.endName = [NSString stringWithFormat:@"%@",self.dic[@"endStake"]];
                self.num = [NSString stringWithFormat:@"%@",self.dic[@"num"]];
                self.time = self.dic[@"inspectionDate"];
                self.peopleName = self.dic[@"inspectionUserName"];
                self.peopleId = self.dic[@"inspectionUser"];
                self.detail = self.dic[@"remark"];
                [self.imgArray removeAllObjects];
                if ([self.dic[@"filePath"] length]==0) {
                    
                }else{
                [self.imgArray addObjectsFromArray: [self.dic[@"filePath"] componentsSeparatedByString:@","]];
                }
                
                [self.tableView reloadData];
            }else{
                if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                    [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                }            }
        }else{
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES];
        }
    }];
}
- (void)setAddWebData{
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
 [NetWorkTool addSearchForDiseaseblock:^(id data) {
     [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
     if (data) {
         if ([data[@"success"] integerValue]) {
             [self.dmdiseaseFormArray removeAllObjects];
             [self.dmdiseaseFormArray addObjectsFromArray:data[@"data"][@"DmDiseaseFormList"]];
             
             [self.bdRouteArray removeAllObjects];
             [self.bdRouteArray addObjectsFromArray:data[@"data"][@"bdRouteList"]];
             
             [self.dictDiseaseTypeArray removeAllObjects];
             [self.dictDiseaseTypeArray addObjectsFromArray:data[@"data"][@"dictDiseaseTypeList"]];
             
             [self.dictDiseaseUnitArray removeAllObjects];
             [self.dictDiseaseUnitArray addObjectsFromArray:data[@"data"][@"dictDiseaseUnitList"]];
             
             [self.dictDrivingDirectionArray removeAllObjects];
             [self.dictDrivingDirectionArray addObjectsFromArray:data[@"data"][@"dictDrivingDirectionList"]];
             
             [self.dictLanePositionArray removeAllObjects];
             [self.dictLanePositionArray addObjectsFromArray:data[@"data"][@"dictLanePositionList"]];
             
             
             [self.dictWeatherCodeArray removeAllObjects];
             [self.dictWeatherCodeArray addObjectsFromArray:data[@"data"][@"dictWeatherCodeList"]];
             
             [self.maintainOrgArray removeAllObjects];
             [self.maintainOrgArray addObjectsFromArray:data[@"data"][@"maintainOrgList"]];
             
             if (self.state==0) {
                 self.peopleName = [Userdefault getUser][@"userName"];
                 NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
                 [formatter setDateFormat:@"yyyy-MM-dd"];
                 NSString *datetime = [formatter stringFromDate:[NSDate date]];
                 //默认选择
                 self.time = datetime;
                 [self.tableView reloadData];
             }else{
                 [self setWebData];
             }
         }else{
             if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                 [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                 [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
             }else{
                 [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
             }         }
     }else{
         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES];
     }
 }];
}
#pragma mark - Delegate
- (void)locationForIphoneWithIndexPath:(NSIndexPath *)indexPath{
   
   [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    [NetWorkTool getZhuangNumWithLng:self.longitude lat:self.latitude block:^(id data) {
      
        [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
        if (data) {
            if ([data[@"success"] integerValue]) {
                NSCharacterSet *cs;
                cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
                
                NSString *filtered = [[data[@"data"][@"stake"] componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
               
                if (self.bdRouteName == nil) {
                    self.bdRouteId = data[@"data"][@"routeId"];
                    self.bdRouteName = data[@"data"][@"routeCode"];
                    self.receiveMan = nil;
                    self.receiveManId = nil;
                    self.receiveDepartment = nil;
                    self.receiveDepartmentId = nil;
                    if (indexPath.row==5) {
                        self.startName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"定位桩号与路线成功！" animated:YES];
                    }else if (indexPath.row==6){
                        self.endName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"定位桩号与路线成功！" animated:YES];
                    }else{
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"定位路线成功！" animated:YES];
                    }

                    for (NSDictionary *dic in self.bdRouteArray) {
                        if ([data[@"data"][@"routeCode"] isEqualToString:dic[@"routeCode"]]) {
                            self.maintainOrgId = dic[@"maintainUnitId"];
                            self.maintainOrgName = dic[@"maintainUnitName"];
                        }
                    }
                    [self.tableView reloadData];
                }else if ([self.bdRouteName isEqualToString:data[@"data"][@"routeCode"]]) {
                    
                    if (indexPath.row==5) {
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"定位桩号成功！" animated:YES];
                        self.startName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];
                    }else if(indexPath.row==6){
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"定位桩号成功！" animated:YES];
                        self.endName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];
                    }else{
                         [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"定位路线成功！" animated:YES];
                        self.bdRouteId = data[@"data"][@"routeId"];
                        self.bdRouteName = data[@"data"][@"routeCode"];
                    }
                    [self.tableView reloadData];
                }else{
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"当前定位所在路线为%@,是否更改路线?",data[@"data"][@"routeCode"]] message:nil preferredStyle:UIAlertControllerStyleAlert];
                        [actionSheet addAction:[UIAlertAction actionWithTitle:@"更改" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            self.bdRouteId = data[@"data"][@"routeId"];
                            self.bdRouteName = data[@"data"][@"routeCode"];
                            if (indexPath.row==5) {
                                self.startName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];;
                                self.endName = nil;
                            }else if(indexPath.row==6){
                                self.endName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];;
                                self.startName = nil;
                            }else{
                                self.startName = nil;
                                self.endName = nil;
                            }
                            self.receiveMan = nil;
                            self.receiveManId = nil;
                            self.receiveDepartment = nil;
                            self.receiveDepartmentId = nil;
                            for (NSDictionary *dic in self.bdRouteArray) {
                                if ([data[@"data"][@"routeCode"] isEqualToString:dic[@"routeCode"]]) {
                                    self.maintainOrgId = dic[@"maintainUnitId"];
                                    self.maintainOrgName = dic[@"maintainUnitName"];
                                }
                            }
                            [self.tableView reloadData];
                        }]];
                
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self presentViewController:actionSheet animated:YES completion:nil];
                    });

                }
                
            }else{
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"附近没有相应的路线和桩号!" animated:YES];
            }
        }else{
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误" animated:YES];
        }
    }];
}
- (void)picsForIphoneWithImgArray:(NSMutableArray *)arr AndDeleteArray:(NSMutableArray *)deleteArray{
    [self.imgArray removeAllObjects];
    [self.deleteArray removeAllObjects];
    [self.imgArray addObjectsFromArray:arr];
    [self.deleteArray addObjectsFromArray:deleteArray];
}
- (void)detailForIPhoneCellWithString:(NSString *)str indexPath:(NSIndexPath *)indexPath{
    self.detail = str;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if ([self.imgArray count]==0&&self.state==2) {
        return 2;
    }else{
       return 3;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 16;
            break;
        case 1:
            return 1;
            break;
        default:
            return 1;
            break;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 45*WidthRate;
    }else{
        return 135*WidthRate;
    }
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.state !=2) {
        if (indexPath.section==0) {
            switch (indexPath.row) {
                case 0:
                {
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"路线编码" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                    for (int i = 0; i<self.bdRouteArray.count; i++) {
                        [actionSheet addAction:[UIAlertAction actionWithTitle:self.bdRouteArray[i][@"routeCode"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            self.bdRouteName = self.bdRouteArray[i][@"routeCode"];
                            self.bdRouteId = self.bdRouteArray[i][@"routeId"];
                            self.maintainOrgId = self.bdRouteArray[i][@"maintainUnitId"];
                            self.maintainOrgName = self.bdRouteArray[i][@"maintainUnitName"];
                            self.receiveMan = nil;
                            self.receiveManId = nil;
                            self.receiveDepartmentId = nil;
                            self.receiveDepartment = nil;
                            self.startName = nil;
                            self.endName = nil;
                            [self.tableView reloadData];
                            
                        }]];
                    }
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                   dispatch_async(dispatch_get_main_queue(), ^{
                    [self presentViewController:actionSheet animated:YES completion:nil];
                   });

                }
                    break;
                case 1:
                {
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"管养单位" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                    for (int i = 0; i<self.maintainOrgArray.count; i++) {
                        [actionSheet addAction:[UIAlertAction actionWithTitle:self.maintainOrgArray[i][@"orgName"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            self.maintainOrgId = self.maintainOrgArray[i][@"orgId"];
                            self.maintainOrgName = self.maintainOrgArray[i][@"orgName"];
                            self.receiveMan = nil;
                            self.receiveManId = nil;
                            self.receiveDepartmentId = nil;
                            self.receiveDepartment = nil;
                            PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.maintainOrgName;
                            PutNormolForIPhoneCell *cell1 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
                            cell1.contentLab.text = self.receiveDepartment;
                            PutNormolForIPhoneCell *cell2 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]];
                            cell2.contentLab.text = self.receiveMan;
                        }]];
                    }
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self presentViewController:actionSheet animated:YES completion:nil];
                    });
                }
                    break;
                case 2:
                {
                      if (self.maintainOrgId) {
                          [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
                          [NetWorkTool receiveDepartmentWithUnitID:self.maintainOrgId block:^(id data) {
                              [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                              if (data) {
                                  if([data[@"success"] integerValue]){
                                      UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"接收部门" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                                      for (int i = 0; i<[data[@"data"] count]; i++) {
                                          [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"orgName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                              self.receiveDepartment = data[@"data"][i][@"orgName"];
                                              self.receiveDepartmentId = data[@"data"][i][@"orgId"];
                                              self.receiveMan = nil;
                                              self.receiveManId = nil;
                                              PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
                                              cell.contentLab.text = self.receiveDepartment;
                                              PutNormolForIPhoneCell *cell1 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]];
                                              cell1.contentLab.text = self.receiveMan;
                                          }]];
                                      }
                                      [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                                      
                                      dispatch_async(dispatch_get_main_queue(), ^{
                                          [self presentViewController:actionSheet animated:YES completion:nil];
                                      });
                                      
                                  }else{
                                      
                                      [PublicMethod noTokenToLoginWithNav:self.navigationController];
                                  }
                                  
                              }else{
                                  [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取接收部门失败" animated:YES];
                              }
                              
                          }];

                      
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"请先选择管养单位" animated:YES];
                    
                }
                }
                    break;
                case 3:
                {
                      if ([self.receiveDepartmentId length]>0) {
                          [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
                          [NetWorkTool receiveManWithUnitID:self.receiveDepartmentId block:^(id data) {
                             [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                              if (data) {
                                  if([data[@"success"] integerValue]){
                                      UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"接收人" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                                      for (int i = 0; i<[data[@"data"] count]; i++) {
                                          [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                              self.receiveMan = data[@"data"][i][@"userName"];
                                              self.receiveManId = data[@"data"][i][@"userId"];
                                              PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]];
                                              cell.contentLab.text = self.receiveMan;
                                              
                                          }]];
                                      }
                                      [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                                      
                                      dispatch_async(dispatch_get_main_queue(), ^{
                                          [self presentViewController:actionSheet animated:YES completion:nil];
                                      });
                                      
                                  }else{
                                      
                                      [PublicMethod noTokenToLoginWithNav:self.navigationController];
                                  }
                                  
                              }else{
                                  [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取接收人失败" animated:YES];
                              }
                              
                          }];
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"请先选择接收部门" animated:YES];
                }
                }
                    break;
                case 4:
                {
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"行车方向" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                    for (int i = 0; i<self.dictDrivingDirectionArray.count; i++) {
                        [actionSheet addAction:[UIAlertAction actionWithTitle:self.dictDrivingDirectionArray[i][@"itemName"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            self.dictDrivingDirectionName = self.dictDrivingDirectionArray[i][@"itemName"];
                            self.dictDrivingDirectionId = self.dictDrivingDirectionArray[i][@"itemCode"];
                            PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.dictDrivingDirectionName;
                        }]];
                    }
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self presentViewController:actionSheet animated:YES completion:nil];
                    });
                }
                    break;
                case 5:
                {
                   
                    startAlert = [[UIAlertView alloc]initWithTitle:@"请输入起点桩号" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                    [startAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
                    UITextField *startField = [startAlert textFieldAtIndex:0];
                    startField.placeholder = @"只输入数字即可";
                    startField.keyboardType = UIKeyboardTypeDecimalPad;
                    if ([self.startName integerValue]==[self.startName floatValue]) {
                        if ([self.startName integerValue]==0) {
                            startField.text = nil;
                        }else{
                        startField.text =[NSString stringWithFormat:@"%ld",[self.startName integerValue]];
                        }
                    }else{
                    startField.text = self.startName;
                    }
                    [startField becomeFirstResponder];
                    [startAlert show];
                }
                    break;
                case 6:
                {
                    
                    startAlert = [[UIAlertView alloc]initWithTitle:@"请输入终点桩号" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                    [startAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
                    UITextField *startField = [startAlert textFieldAtIndex:0];
                    startField.placeholder = @"只输入数字即可";
                    startField.keyboardType = UIKeyboardTypeDecimalPad;
                    if ([self.endName integerValue]==[self.endName floatValue]) {
                        if ([self.endName integerValue]==0) {
                            startField.text = nil;
                        }else{
                            startField.text =[NSString stringWithFormat:@"%ld",[self.endName integerValue]];
                        }
                    }else{
                        startField.text = self.endName;
                    }
                    [startField becomeFirstResponder];
                    [startAlert show];
                   
                }
                    break;
                case 7:
                {
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"损坏类型" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                    for (int i = 0; i<self.dictDiseaseTypeArray.count; i++) {
                        [actionSheet addAction:[UIAlertAction actionWithTitle:self.dictDiseaseTypeArray[i][@"itemName"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            self.dictDiseaseTypeName = self.dictDiseaseTypeArray[i][@"itemName"];
                            self.dictDiseaseTypeId = self.dictDiseaseTypeArray[i][@"itemCode"];
                            PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.dictDiseaseTypeName;
                            self.dmdiseaseFormName = nil;
                            self.dmdiseaseFormId = nil;
                            self.damageDegreeName = nil;
                            self.damageDegreeId = nil;
                            self.dictDiseaseUnitName = nil;
                            self.dictDiseaseUnitId = nil;
                            PutNormolForIPhoneCell *cell2 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:8 inSection:0]];
                            cell2.contentLab.text = self.dmdiseaseFormName;
                            
                            PutNormolForIPhoneCell *cell3 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:9 inSection:0]];
                            cell3.contentLab.text = self.damageDegreeName;
                            PutNormolForIPhoneCell *cell4 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:10 inSection:0]];
                            cell4.contentLab.text = self.dictDiseaseUnitName;
                        }]];
                    }
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self presentViewController:actionSheet animated:YES completion:nil];
                    });
                    
                }
                    break;
                case 8:
                {
//                    dispatch_async(dispatch_get_main_queue(), ^{
                    if (self.dictDiseaseTypeId) {
                        [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
                        [NetWorkTool getDiseaseStyle:self.dictDiseaseTypeId block:^(id data) {
                          [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                            if (data) {
                                if([data[@"success"] integerValue]){
                                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"病害形式-程度-单位" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                                    for (int i = 0; i<[data[@"data"] count]; i++) {
                                        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@--%@--%@",data[@"data"][i][@"diseaseFormName"], [[NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseLevelName"]] isEqualToString:@""]?@"空":[NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseLevelName"]],[[NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseUnitName"]] isEqualToString:@""]?@"空":[NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseUnitName"]]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                            self.dmdiseaseFormName = data[@"data"][i][@"diseaseFormName"];
                                            self.dmdiseaseFormId = data[@"data"][i][@"diseaseFormId"];
                                        
                                            self.damageDegreeName = [NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseLevelName"]];
                                            self.damageDegreeId = [NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseLevelCode"]];
                                            if ([self.damageDegreeName isEqualToString:@""]) {
                                                self.damageDegreeName = @"";
                                                self.damageDegreeId = nil;
                                            }
                                            
                                            self.dictDiseaseUnitName = [NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseUnitName"]];
                                            self.dictDiseaseUnitId = [NSString stringWithFormat:@"%@",data[@"data"][i][@"diseaseUnitCode"]];
                                            if ([self.dictDiseaseUnitName isEqualToString:@""]) {
                                                self.dictDiseaseUnitName = @"";
                                                self.dictDiseaseUnitId = nil;
                                            }
                                            
                                            PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:8 inSection:0]];
                                            cell.contentLab.text = self.dmdiseaseFormName;
                                            
                                            PutNormolForIPhoneCell *cell1 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:9 inSection:0]];
                                            cell1.contentLab.text = self.damageDegreeName;
                                            PutNormolForIPhoneCell *cell2 = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:10 inSection:0]];
                                            cell2.contentLab.text = self.dictDiseaseUnitName;
                                        }]];
                                    }
                                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                                    
                                    dispatch_async(dispatch_get_main_queue(), ^{
                                        [self presentViewController:actionSheet animated:YES completion:nil];
                                    });
                                    
                                }else{
                                    
                                    [PublicMethod noTokenToLoginWithNav:self.navigationController];
                                }
                                
                            }else{
                                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取病害形式失败" animated:YES];
                            }
                            
                        }];

                    }else{
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"请先选择损坏类型" animated:YES];
                    }
                    
//                     });
                }
                    break;
                case 9:
                {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"该数值来源于病害形式" animated:YES];
                }
                    break;
                case 10:
                {
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"该数值来源于病害形式" animated:YES];
                }
                    break;
                case 11:
                {
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"车道位置" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                    for (int i = 0; i<self.dictLanePositionArray.count; i++) {
                        [actionSheet addAction:[UIAlertAction actionWithTitle:self.dictLanePositionArray[i][@"itemName"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            self.dictLanePositionName = self.dictLanePositionArray[i][@"itemName"];
                            self.dictLanePositionId = self.dictLanePositionArray[i][@"itemCode"];
                            PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.dictLanePositionName;
                        }]];
                    }
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self presentViewController:actionSheet animated:YES completion:nil];
                    });
                }
                    break;
                case 12:
                {
                    startAlert = [[UIAlertView alloc]initWithTitle:@"请输入数量" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                    [startAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
                    UITextField *startField = [startAlert textFieldAtIndex:0];
                    startField.keyboardType = UIKeyboardTypeDecimalPad;
                    startField.placeholder = @"请输入数量";
                    if ([self.num doubleValue]==0) {
                        startField.text = nil;
                    }else{
                    startField.text = self.num;
                    }
                    [startField becomeFirstResponder];
                    [startAlert show];

                }
                    break;
                case 13:
                {
                    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
                    [NetWorkTool receiveManWithUnitID:nil block:^(id data) {
                        [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
                        if (data) {
                            if([data[@"success"] integerValue]){
                                UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"巡查人" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                                for (int i = 0; i<[data[@"data"] count]; i++) {
                                    [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",data[@"data"][i][@"userName"]]style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                        self.peopleName = data[@"data"][i][@"userName"];
                                        self.peopleId = data[@"data"][i][@"userId"];
                                        PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:13 inSection:0]];
                                        cell.contentLab.text = self.peopleName;
                                    }]];
                                }
                                [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                                
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    [self presentViewController:actionSheet animated:YES completion:nil];
                                });
                                
                            }else{
                                
                                [PublicMethod noTokenToLoginWithNav:self.navigationController];
                            }
                            
                        }else{
                            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"因网络问题获取接收人失败" animated:YES];
                        }
                        
                    }];
                }
                    break;
                case 14:
                {
                    //x,y 值无效，默认是居中的
                    KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, 280, 260)];
                    
                    //配置中心，详情见KSDatePikcerApperance
                    
                    picker.appearance.radius = 5;
                    
                    //设置回调
                    picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
                        
                        if (buttonType == KSDatePickerButtonCommit) {
                            
                            NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
                            [formatter setDateFormat:@"yyyy-MM-dd"];
                            self.time = [formatter stringFromDate:currentDate];
                            PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.time;
                        }
                    };
                    // 显示
                    [picker show];
                }
                    break;
                case 15:
                {
                    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"天气" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                    for (int i = 0; i<self.dictWeatherCodeArray.count; i++) {
                        [actionSheet addAction:[UIAlertAction actionWithTitle:self.dictWeatherCodeArray[i][@"itemName"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                            self.dictWeatherCodeName = self.dictWeatherCodeArray[i][@"itemName"];
                            self.dictWeatherCodeId = self.dictWeatherCodeArray[i][@"itemCode"];
                            PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                            cell.contentLab.text = self.dictWeatherCodeName;
                        }]];
                    }
                    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self presentViewController:actionSheet animated:YES completion:nil];
                    });
                }
                    break;
                default:
                    break;
            }
        }
    }else{
    
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        PutNormolForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:PutCellID];
        cell.titleLab.text = self.titleArray[indexPath.row];
        cell.indexPath = indexPath;
        cell.delegate = self;
        switch (indexPath.row) {
            case 0:
                cell.contentLab.text = self.bdRouteName;
                break;
            case 1:
                cell.contentLab.text = self.maintainOrgName;
                break;
            case 2:
                cell.contentLab.text = self.receiveDepartment;
                break;
            case 3:
                cell.contentLab.text = self.receiveMan;
                break;
            case 4:
                cell.contentLab.text = self.dictDrivingDirectionName;
                break;
            case 5:
            {
                NSString *num = [NSString stringWithFormat:@"%.3f",[self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000];
                if ([num integerValue] == [num floatValue]) {
                    num = [NSString stringWithFormat:@"%ld",[num integerValue]];
                }
                if (([self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000)<10) {
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+00%@",[self.startName integerValue]/1000,num];
                }else if(([self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000)>=10&&([self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000)<100){
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+0%@",[self.startName integerValue]/1000,num];
                }else{
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+%@",[self.startName integerValue]/1000,num];
                }
            }
                break;
            case 6:
            {
                NSString *num = [NSString stringWithFormat:@"%.3f",[self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000];
                if ([num integerValue] == [num floatValue]) {
                    num = [NSString stringWithFormat:@"%ld",[num integerValue]];
                }
                if (([self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000)<10) {
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+00%@",[self.endName integerValue]/1000,num];
                }else if(([self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000)>=10&&([self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000)<100){
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+0%@",[self.endName integerValue]/1000,num];
                }else{
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+%@",[self.endName integerValue]/1000,num];
                }
            }
                break;
            case 7:
                cell.contentLab.text = self.dictDiseaseTypeName;
                break;
            case 8:
                cell.contentLab.text = self.dmdiseaseFormName;
                break;
            case 9:
            {
                if ([self.damageDegreeName length]==0) {
                    cell.contentLab.text = @"";
                }else{
                    cell.contentLab.text = self.damageDegreeName;
                }
                
            }
                break;
            case 10:
            {
                if ([self.dictDiseaseUnitName length]==0) {
                    cell.contentLab.text = @"";
                }else{
                    cell.contentLab.text = self.dictDiseaseUnitName;
                }
                
            }
                break;
            case 11:
                cell.contentLab.text = self.dictLanePositionName;
                break;
            case 12:
                cell.contentLab.text = self.num;
                break;
            case 13:
                cell.contentLab.text = self.peopleName;
                break;
            case 14:
                cell.contentLab.text = self.time;
                break;
            case 15:
                cell.contentLab.text = self.dictWeatherCodeName;
                break;
            default:
                break;
        }
        if (self.state == 2) {
            cell.img.hidden = YES;
        }else{
            if (indexPath.row==5||indexPath.row==6||indexPath.row==0) {
                cell.img.hidden = YES;
                cell.btn.hidden = NO;
                [cell.contentLab mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.mas_equalTo(0);
                    make.bottom.mas_equalTo(0);
                    make.left.equalTo(cell.titleLab.mas_right).offset(0);
                    make.right.equalTo(cell.img.mas_left).offset(-10*WidthRate);
                }];
            }else if(indexPath.row==9||indexPath.row==10){
                cell.img.hidden = YES;
                cell.btn.hidden = YES;
                [cell.contentLab mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.mas_equalTo(0);
                    make.bottom.mas_equalTo(0);
                    make.left.equalTo(cell.titleLab.mas_right).offset(0);
                    make.right.equalTo(cell.img.mas_left).offset(0);
                }];
            }else{
                cell.img.hidden = NO;
                cell.btn.hidden = YES;
                cell.img.image = [UIImage imageNamed:@"enter"];
                [cell.contentLab mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.mas_equalTo(0);
                    make.bottom.mas_equalTo(0);
                    make.left.equalTo(cell.titleLab.mas_right).offset(0);
                    make.right.equalTo(cell.img.mas_left).offset(0);
                }];
            }
        }
        
        return  cell;
    } else if(indexPath.section==1){
        if (self.state == 2&&[self.imgArray count]==0) {
            SearchForDiseaseForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellID];
            cell.delegate = self;
            cell.indexPath = indexPath;
            if (self.state == 2) {
                cell.detailTextView.editable = NO;
                cell.detailTextView.placeholder = @" ";
            }else{
                cell.detailTextView.editable = YES;
                cell.detailTextView.placeholder = @"请输入备注内容";
            }
            
            cell.detailTextView.text = self.detail;
            cell.titleLab.text = @"备注";
            return  cell;
        }else{
            SearchForDiseaseAddPicsForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:PicCellID];
            cell.delegate = self;
            if (self.state==2) {
                cell.isReset = NO;
            }else{
                cell.isReset = YES;
            }
            cell.titleLab.text = @"病害照片";
            cell.con = self;
            [cell addValue:self.imgArray];
            return  cell;
        }
    }else{
        SearchForDiseaseForIPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellID];
        cell.delegate = self;
        cell.indexPath = indexPath;
        if (self.state == 2) {
            cell.detailTextView.editable = NO;
            cell.detailTextView.placeholder = @" ";
        }else{
            cell.detailTextView.editable = YES;
            cell.detailTextView.placeholder = @"请输入备注内容";
        }
        
        cell.detailTextView.text = self.detail;
        cell.titleLab.text = @"备注";
        return  cell;
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([alertView.title isEqualToString:@"上报"]) {
        if (buttonIndex) {
            [self endPutData];
        }
    }else if ([alertView.title isEqualToString:@"删除"]) {
        if (buttonIndex==1) {
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            [NetWorkTool getSearchForDiseaseDeleteWithID:self.codeId block:^(id data) {
           [MBProgressHUD hideAllHUDsForView:self.view animated:NO];
                if (data) {
                    if ([data[@"success"] integerValue]) {
                        [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"删除成功" animated:YES];
                        [self performSelector:@selector(pop) withObject:nil afterDelay:1];
                        
                    }else{
                        if ([data[@"message"] isEqualToString:@"请求需要进行验证,请重新传入Token"]) {
                            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"账号被其他设备登录，请重新登录" animated:YES];
                            [self performSelector:@selector(gotoLogin) withObject:nil afterDelay:1];
                        }else{
                            [MBProgressHUD showTextHUDAddedTo:self.view Msg:data[@"message"] animated:YES];
                        }                    }
                }else{
                    [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，请检查网络后重试。" animated:YES];
                }
            }];
            
        }
    }else if ([alertView.title isEqualToString:@"请输入起点桩号"]) {
        if (buttonIndex == alertView.firstOtherButtonIndex) {
            UITextField* textField = [alertView textFieldAtIndex:0];
            if([textField.text removeSpace].length==0){
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"起点桩号为空" animated:YES];
                return;
            }else{
                NSCharacterSet *cs;
                cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
                
                NSString *filtered = [[textField.text componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
                self.startName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];
                PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:0]];
                NSString *num = [NSString stringWithFormat:@"%.3f",[self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000];
                if ([num integerValue] == [num floatValue]) {
                    num = [NSString stringWithFormat:@"%ld",[num integerValue]];
                }
                if (([self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000)<10) {
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+00%@",[self.startName integerValue]/1000,num];
                }else if(([self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000)>=10&&([self.startName doubleValue]-floor([self.startName doubleValue]/1000)*1000)<100){
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+0%@",[self.startName integerValue]/1000,num];
                }else{
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+%@",[self.startName integerValue]/1000,num];
                }
            }
    }
    }else if ([alertView.title isEqualToString:@"请输入终点桩号"]) {
        if (buttonIndex == alertView.firstOtherButtonIndex) {
            UITextField* textField = [alertView textFieldAtIndex:0];
            if([textField.text removeSpace].length==0){
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"终点桩号为空" animated:YES];
                return;
            }else{
                NSCharacterSet *cs;
                cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
                
                NSString *filtered = [[textField.text componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
                self.endName = [NSString stringWithFormat:@"%.3f",[filtered doubleValue]];
                PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:6 inSection:0]];
                NSString *num = [NSString stringWithFormat:@"%.3f",[self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000];
                if ([num integerValue] == [num floatValue]) {
                    num = [NSString stringWithFormat:@"%ld",[num integerValue]];
                }
                if (([self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000)<10) {
                  cell.contentLab.text = [NSString stringWithFormat:@"K%ld+00%@",[self.endName integerValue]/1000,num];
                }else if(([self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000)>=10&&([self.endName doubleValue]-floor([self.endName doubleValue]/1000)*1000)<100){
                    cell.contentLab.text = [NSString stringWithFormat:@"K%ld+0%@",[self.endName integerValue]/1000,num];
                }else{
                cell.contentLab.text = [NSString stringWithFormat:@"K%ld+%@",[self.endName integerValue]/1000,num];
                }
            }
        }
    }else{
        
        if (buttonIndex == alertView.firstOtherButtonIndex) {
            UITextField* textField = [alertView textFieldAtIndex:0];
            if([textField.text removeSpace].length==0){
                [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"输入数量为空" animated:YES];
                return;
            }else{
                NSCharacterSet *cs;
                cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
                
                NSString *filtered = [[textField.text componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
                self.num =[PublicMethod changeFloat:[NSString stringWithFormat:@"%f",[filtered doubleValue]]];
                
                PutNormolForIPhoneCell *cell = (PutNormolForIPhoneCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:12 inSection:0]];
                cell.contentLab.text = self.num;
            }
        }
    }
}
@end
